package com.example.module_base.Base;

import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.Toast;

import java.text.SimpleDateFormat;



/**
 * Created by Administrator on 2017/11/3.
 */

public abstract class BaseActivity<B extends ViewDataBinding> extends AppCompatActivity {
    public B bingding;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        bingding= DataBindingUtil.setContentView(this,setLayout());
        init(bingding);
    }
    public abstract int setLayout();
    public abstract void init(B bingding);
    public void toast(Object s){
        Toast.makeText(this, String.valueOf(s), Toast.LENGTH_SHORT).show();
    }

     public void addToolBar(final LinearLayout linearLayout, Toolbar toolbar){
         Toolbar.LayoutParams params = new Toolbar.LayoutParams(Toolbar.LayoutParams.MATCH_PARENT,
         Toolbar.LayoutParams.WRAP_CONTENT);
         // 取控件aaa当前的布局参数
         params.height = dip2px(45.0f);        // 当控件的高强制设成150象素
         params.width=Toolbar.LayoutParams.MATCH_PARENT;
         linearLayout.addView(toolbar,0,params);
     }
    public void addToolBar(final FrameLayout framelayout, Toolbar toolbar){
        Toolbar.LayoutParams params = new Toolbar.LayoutParams(Toolbar.LayoutParams.MATCH_PARENT,
                Toolbar.LayoutParams.WRAP_CONTENT);
        // 取控件aaa当前的布局参数
        params.height = dip2px(45.0f);        // 当控件的高强制设成150象素
        params.width=Toolbar.LayoutParams.MATCH_PARENT;
        framelayout.addView(toolbar,1,params);
    }
     public int dip2px(float dip){
     return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,dip,getResources().getDisplayMetrics());
     }
}
